﻿@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = T("Admin.ContentManagement.Blog.Comments").Text;
    string filterByBlogPostId = ViewBag.FilterByBlogPostId;
}

<div class="row">
    <div class="col-md-12">
        <div class="x_panel light form-fit">
            <div class="x_title">
                <div class="caption level-caption">
                    <i class="fa fa-comment"></i>
                    @T("Admin.ContentManagement.Blog.Comments")
                </div>
            </div>
            <div class="x_content form">
                <div class="form-horizontal">
                    <div class="form-body">
                        <div class="x_content">
                            <div id="comments-grid"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@{
    string readUrl = "";
    if (!string.IsNullOrEmpty(filterByBlogPostId))
    {
        readUrl = Url.Action("Comments", "Blog", new { filterByBlogPostId = filterByBlogPostId });
    }
    else
    {
        readUrl = Url.Action("Comments", "Blog");
    }
}
<script>
    $(document).ready(function () {
        $("#comments-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@readUrl",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    },
                    destroy: {
                        url: "@Html.Raw(Url.Action("CommentDelete", "Blog"))",
                        type: "POST",
                        dataType: "json",
                        data: addAntiForgeryToken
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors",
                    model: {
                        id: "Id",
                        fields: {
                            //do not implicitly specify all fields
                            //we do it only for fields which implicitly require it
                            //otherwise, they'll be formatted wrong way
                            CreatedOn: {type: "date" }
                        }
                    }
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(adminAreaSettings.DefaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(adminAreaSettings.GridPageSizes)]
            },
            editable: {
                confirmation: true,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "BlogPostTitle",
                title: "@T("Admin.ContentManagement.Blog.Comments.Fields.BlogPost")",
                width: 200,
                encoded: false,
                template: '<a class="k-link" href="@Url.Action("Edit", "Blog")/#=BlogPostId#">#:kendo.htmlEncode(BlogPostTitle)#</a>'
            }, {
                field: "CustomerId",
                title: "@T("Admin.ContentManagement.Blog.Comments.Fields.Customer")",
                width: 200,
                template: '<a class="k-link" href="@Url.Action("Edit", "Customer")/#=CustomerId#">#:kendo.htmlEncode(CustomerInfo)#</a>'
            }, {
                field: "Comment",
                title: "@T("Admin.ContentManagement.Blog.Comments.Fields.Comment")",
                encoded: false
            }, {
                field: "CreatedOn",
                title: "@T("Admin.ContentManagement.Blog.Comments.Fields.CreatedOn")",
                width: 200,
                type: "date",
                format: "{0:G}"
            }, {
                command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                title: "@T("Admin.Common.Delete")",
                width: 100
            }]
        });
    });
</script>